package com.xiaochong.tir.manager.util;


import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xiaochong.tir.manager.enums.StatusEnum;

/**
 * 接口统一返回数据定义
 * @author mengying
 * @date 2017/12/23 13:34
 */
public class ResultEntity<E>{

    /**
     * 状态码
     */
    private int code;
    private String resultDes;
    private E result;

    public ResultEntity() {
    }

    public ResultEntity(StatusEnum status, E result) {
        this.code = status.getCode();
        this.resultDes = status.getValue();
        this.result = result;
    }

    public ResultEntity(int code, String resultDes, E result) {
        this.code = code;
        this.resultDes = resultDes;
        this.result = result;
    }

    public void setStatus(StatusEnum status) {
        this.code = status.getCode();
        this.resultDes = status.getValue();
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getResultDes() {
        return resultDes;
    }

    public void setResultDes(String resultDes) {
        this.resultDes = resultDes;
    }

    public E getResult() {
        return result;
    }

    public void setResult(E result) {
        this.result = result;
    }

    @Override
    public String toString() {
        return "ResultEntity [code=" + code + ", resultDes=" + resultDes + ", result=" + result + "]";
    }

    public String toJSONString() {
        String result = JSONObject.toJSONString(this, SerializerFeature.BrowserCompatible);
        return result;
    }
}
